package com.ivan.hospital.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ivan.common.result.Result;
import com.ivan.hospital.service.BookingRuleService;
import com.ivan.model.entity.hosp.BookingRule;
import com.ivan.model.vo.hosp.BookingRuleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
 * @Author      Ivan
 * @Date        2023/4/6 9:05
 * @Description BookingRuleController
 */
@Api(tags = "医院预约规则管理接口")
//@CrossOrigin//使用gateway后做了配置
@RestController
@RequestMapping("/admin/hosp/bookingRule")
public class BookingRuleController {

    @Autowired
    private BookingRuleService bookingRuleService;

    @ApiOperation(value = "条件查询医院预约规则带分页")
    @GetMapping("/findByPage/{current}/{limit}")
    public Result findByPage(@PathVariable("current") long current,
                             @PathVariable("limit") long limit,
                             BookingRuleVo queryVo) {
        Page<BookingRule> page = bookingRuleService.findByPage(current, limit, queryVo);
        return Result.ok(page);
    }

    @ApiOperation(value = "根据id查询医院预约规则")
    @GetMapping("/findById/{id}")
    public Result findById(@PathVariable("id") Long id) {
        BookingRule bookingRule = bookingRuleService.findById(id);
        return Result.ok(bookingRule);
    }

    @ApiOperation(value = "添加医院预约规则")
    @PostMapping("/saveBookingRule")
    public Result saveBookingRule(@RequestBody BookingRule BookingRule) {
        int save = bookingRuleService.saveBookingRule(BookingRule);
        if (save > 0) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }

    @ApiOperation(value = "根据id删除医院预约规则")
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable("id") Long id) {
        int delete = bookingRuleService.removeById(id);
        if (delete > 0) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }

    @ApiOperation(value = "根据idList批量删除医院预约规则")
    @DeleteMapping("/batchDelete")
    public Result batchDelete(@RequestBody List<Long> idList) {
        int delete = bookingRuleService.removeByIds(idList);
        if (delete > 0) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }

    @ApiOperation(value = "修改医院预约规则")
    @PostMapping("/updateBookingRule")
    public Result updateBookingRule(@RequestBody BookingRule bookingRule) {
        int update = bookingRuleService.updateBookingRule(bookingRule);
        if (update > 0) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }
}
